<%@ page language="java" import="java.util.*" import="java.text.SimpleDateFormat" pageEncoding="UTF-8"%>
<%@ page import="com.bluesky.light.user.*"%>
<%
request.setCharacterEncoding("utf-8");
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%
	// check if the user is login
	User u = (User)session.getAttribute("user");
	if (u == null) {
		response.sendRedirect("index.jsp");
	}	
	String name = u.getName();
%>
<%
	
	String action = request.getParameter("action");
	
	if (action != null && action.trim().equals("changeinfo")) {

		name = request.getParameter("name");
		String idcard = request.getParameter("idcard");
		String sex = request.getParameter("sex");	
		String birth_year = request.getParameter("birth_year");
		String birth_month = request.getParameter("birth_month");
		String birth_day = request.getParameter("birth_day");
		String phone = request.getParameter("phone");
		String addr = request.getParameter("addr");
		
		Calendar cal = Calendar.getInstance();
		cal.clear();
		cal.set(Integer.parseInt(birth_year), (Integer.parseInt(birth_month)-1), Integer.parseInt(birth_day));
		Date birth = cal.getTime();
		
		u.setName(name);
		u.setIdcard(idcard);
		u.setSex(sex);
		u.setBirth(birth);
		u.setPhone(phone);
		u.setAddr(addr);
		UserService.getInstance().update(u);
		response.sendRedirect("user_infoModify.jsp");
		return;
	}
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>light - change info</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<link href="css/main.css" rel="stylesheet" type="text/css" />

			<script language=JavaScript  src="js/checkinfo.js"> 
	</script>
	
  </head>
  
  <body onload = "checkAge(changeinfo.birth_year.value,changeinfo.birth_month.value)">
	<!-- header -->
	<div id="header">
		<div id="logo"><img src="images/logo_small2.png"/></div>
	</div>
	<!-- // header -->
	<!-- nav -->
	<div id="nav">
	</div>
	<!-- // nav -->
	<!-- container -->
	<div id="container">
		<!-- contents -->
		<div id="contents">
	    	<div id="menu">
	        	<div>
	        		<div id="user_info">
	            		<img src="develop/user_icon.jpg"/> 
	            		<b>User</b>
	           		</div>
	           		<div>
	           		<%=name%>
	           		</div>
	            </div>
	            <div>
	            	<%SimpleDateFormat sdf = new SimpleDateFormat("EEE, yyyy-MM-dd", new Locale("US"));%><%=sdf.format(new Date())%><br></br>
	            </div>
	        	<ul>
	            	<li><a href="home.jsp"><img src="images/news.png" /> Health News</a></li>
					<li><a href="user_subscribe.jsp"><img src="images/surscribe.png" /> Appointment</a></li>
					<li><a href="user_history.jsp"><img src="images/account.png" /> Health History</a></li>
					<li><a href="user_hospitalSearchOnMap.jsp"><img src="images/photo.png" /> Searching Hospital</a></li>
					<li><a href="user_bodyCheckResult.jsp"><img src="images/surscribe.png" /> Body Check Result</a></li>
					<li>
						<a href="user_infoModifyInput.jsp"><img src="images/account.png" /> Account Management</a>
						<ul>
						<li><a href="user_pwdModifyInput.jsp">Change password</a></li>
						<li><a href="user_infoModifyInput.jsp">Change personal info</a></li>
						</ul>
					</li>
	            </ul>	            
	        </div>
	        <div id="main-cont">
	        	<div id="regist_form">
	                <form action="user_infoModifyInput.jsp" name="changeinfo" method="post" onSubmit="return checkdata()" >
	                	<input type="hidden" name="action" value="changeinfo" />
	                    <h2>Change personal information</h2>
	                    <table>
	                    	<tr><td>Name: </td><td><input name="name" value="<%=u.getName()%>" type="text" onblur = "checkName(this.value)"/>
	                    	<span id = "nameErr"></span><br></td></tr>	
	                    	<tr><td>ID card: </td><td><input name="idcard" value="<%=u.getIdcard()%>" type="text" onblur = "checkid(this.value)"/>
	                    	<span id = "idErr"></span><br></td></tr>	                        
	                        <tr><td>Sex: </td><td><select name = "sex">
	                    		<option value="M" >Male</option>
	                    		<option value="F" <%=((u.getSex().equals("F")?"selected":""))%>>Female</option>
	                    	</select></td></tr>
	                        <tr><td>Birth: </td>
	                        <!--<td><input name="age" value="<%=u.getBirth() %>" type="hidden" onblur = "checkAge(this.value)"/>
	                         <span id = "ageErr"></span><br></td> -->
		                         <td>
			                    	<select name = "birth_year"  onblur = "checkAge(changeinfo.birth_year.value,changeinfo.birth_month.value)">
			                    		<option value="1990">1990</option>
			                    		<option value="1991">1991</option>
			                    		<option value="1992">1992</option>
			                    		<option value="1993">1993</option>
			                    		<option value="1994">1994</option>
			                    		<option value="1995">1995</option>
			                    		<option value="1996">1996</option>
			                    		<option value="1997">1997</option>
			                    		<option value="1998">1998</option>
			                    		<option value="1999">1999</option>
			                    	</select>
			                    	<select name = "birth_month" onblur = "checkAge(changeinfo.birth_year.value,changeinfo.birth_month.value)">
			                    		<option value="1">1</option>
			                    		<option value="2">2</option>
			                    		<option value="3">3</option>
			                    		<option value="4">4</option>
			                    		<option value="5">5</option>
			                    		<option value="6">6</option>
			                    		<option value="7">7</option>
			                    		<option value="8">8</option>
			                    		<option value="9">9</option>
			                    		<option value="10">10</option>
			                    		<option value="11">11</option>
			                    		<option value="12">12</option>
			                    	</select>
			                    	<select name = "birth_day" >
			                    		<option value="1">1</option>
			                    		<option value="2">2</option>
			                    		<option value="3">3</option>
			                    		<option value="4">4</option>
			                    		<option value="5">5</option>
			                    		<option value="6">6</option>
			                    		<option value="7">7</option>
			                    		<option value="8">8</option>
			                    		<option value="9">9</option>
			                    		<option value="10">10</option>
			                    		<option value="11">11</option>
			                    		<option value="12">12</option>
			                    		<option value="13">13</option>
			                    		<option value="14">14</option>
			                    		<option value="15">15</option>
			                    		<option value="16">16</option>
			                    		<option value="17">17</option>
			                    		<option value="18">18</option>
			                    		<option value="19">19</option>
			                    		<option value="20">20</option>
			                    		<option value="21">21</option>
			                    		<option value="22">22</option>
			                    		<option value="23">23</option>
			                    		<option value="24">24</option>
			                    		<option value="25">25</option>
			                    		<option value="26">26</option>
			                    		<option value="27">27</option>
			                    		<option value="28">28</option>
			                    	</select>
			                    	<!--<span id = "birthErr"></span><br> -->
			                    </td>
	                        </tr>
	                        <tr><td>Phone: </td><td><input name="phone" value="<%=u.getPhone()%>" type="text" onblur = "checkphone(this.value)"/>
	                        <span id = "phoneErr"></span><br></td></tr>
	                        <tr><td>Address: </td><td><input name="addr" value="<%=u.getAddr()%>" type="text" onblur = "checkaddress(this.value)"/>
	                        <span id = "addressErr"></span><br></td></tr>
	                        <tr><td/><td/></tr>
	                        <tr><td colspan="2" align="center"><input type="submit" value="OK! Change it!"/></td></tr>                     
	                    </table>
	                </form>
	       		</div>
	        </div>
	    </div>
	    <!-- // contents -->
	</div>
	<!-- // container -->
	<div id="footer">
		<div id="bs_stdio">
	    	©2011-2011 www.bluesky.com.mo All Rights Reserved<br/>
	    	<img src="images/bluesky_logo.png" />
	    </div>
	</div>
  </body>
</html>
